<?php
/**
 * 类名：Cff_Cookie.php
 * 功能：Cookie常用操作
 */

class Cff_Cookie{
    static $PREFIX='';
    static function setPrefix($a=''){
        if($a==''){
            self::$PREFIX = COOKIE_PREFIX;
        }else{
            self::$PREFIX=$a;
        }
    }
    // 判断Cookie是否存在
    static function is_set($name) {
        return isset($_COOKIE[self::$PREFIX.$name]);
    }

    // 获取某个Cookie值
    static function get($name) {
        $value = $_COOKIE[self::$PREFIX.$name];
        $value =  base64_decode(unserialize($value));
        return $value;
    }

    // 设置某个Cookie值
    static function set($name,$value,$expire='',$path='',$domain='') {
        if($expire=='') {
            $expire = COOKIE_EXPIRE;
        }
        if(empty($path)) {
            $path = COOKIE_PATH;
        }
        if(empty($domain)) {
            $domain = COOKIE_DOMAIN;
        }
        $expire = !empty($expire)?    time()+$expire   :  0;
        $value =  base64_encode(serialize($value));
        setcookie(self::$PREFIX.$name, $value,$expire,$path,$domain);
        $_COOKIE[self::$PREFIX.$name]  =   $value;
    }

    // 删除某个Cookie值
    static function delete($name) {
        self::set($name,'',time()-3600);
        unset($_COOKIE[self::$PREFIX.$name]);
    }

    // 清空Cookie值
    static function clear() {
        unset($_COOKIE);
    }
}
?> 